/**
 * 给你单链表的头结点head, 请你反转链表，并返回反转后的链表
 * 示例1:
 * 1->2->3->4->5
 * 5->4->3->2->1
 * 示例2:
 * 1->2
 * 2->1
*/
function Node (data) {
    this.data = data;
    this.next = null;
}

const node1 = new Node(1);
const node2 = new Node(2);
const node3 = new Node(3);
const node4 = new Node(4);
const node5 = new Node(5);

node1.next = node2;
node2.next = node3;
node3.next = node4;
node4.next = node5;

function reverseList (head) {
    let pre = null;
    let curr = head;
    while (curr) {
        // 解构并且重新赋值
        [curr.next, pre, curr] = [pre, curr, curr.next]
    }
    return pre;
}

console.log(reverseList(node1));
